package com.phoenix.jsef.demo.service;

import com.phoenix.jsef.demo.dao.COzBkHeaderRepository;
import com.phoenix.jsef.demo.pojo.COzBkHeaderEntity;
import com.phoenix.jsef.demo.pojo.COzBkHeaderTags;
import com.phoenix.jsef.demo.shared.IBizOzBkHeader;
import com.phoenix.jsef.framework.AccessParameter;
import com.phoenix.jsef.framework.EntityCollection;
import com.phoenix.jsef.framework.PageInfo;
import com.phoenix.jsef.jdbcutils.CommandType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**   
 * @ClassName:  CBizOzBkHeader   
 * @Description:TODO(商业实体对象:COzBkHeaderEntity对应提供的服务具体实现)   
 * @author: 李启联
 * @date:   2018-8-1 17:35:22  
 * @version V1.0     
 * @Copyright: Copyright (c) 2018
 * 申明：本内容未经作者本人同意,禁止外泄以及用于其他的商业项目.
 */
@Service
@CacheConfig(cacheNames="BizOzBkHeader_Cache")
public class CBizOzBkHeader implements IBizOzBkHeader {


	@Autowired
	//private  COzBkHeaderDataAccess access;
    private COzBkHeaderRepository access;

	@Override
    @Cacheable()
	public EntityCollection getCollection(Map<String,Object> filter) throws Exception {
        access.getAccessParameter().getFilter().addAllEqual(filter);
        return access.searchEntityCollection();

	}

    @Override
    @Cacheable()
    public List<COzBkHeaderEntity> getList(Map<String,Object> filter) throws Exception {
        AccessParameter accessParameter =  access.getAccessParameter();
        accessParameter.getFilter().cleanFilter();
        accessParameter.getFilter().addAllEqual(filter);
        return (List<COzBkHeaderEntity>) access.searchEntityList();
    }


    @Override
    @Cacheable()
    public List<COzBkHeaderEntity> getListBySql(CommandType commandType, String commandText, Object... obj) throws Exception {
        return (List<COzBkHeaderEntity>)access.searchEntityListBySQL(commandType,commandText,obj);
    }

    @Override
    @Cacheable(key="#root.targetClass+':'+#root.methodName+':'+#filter+':'+#pageIndex+':'+#pageSize")
    public  PageInfo<COzBkHeaderEntity> getPageInfo(Map<String, Object> filter, Map<String, String> sorter,
            Integer pageIndex, Integer pageSize) throws Exception {

        AccessParameter accessParameter =  access.getAccessParameter();

        if(null != filter) {
            accessParameter.getFilter().addAllEqual(filter);
        }
        if(null != sorter) {
            for(Map.Entry<String,String> entry : sorter.entrySet()){
                if(entry.getValue() != null && entry.getValue().trim().length() > 0)
                    accessParameter.getSorter().add(entry.getKey(), entry.getValue());
            }
        }
        accessParameter.setPageSize(pageSize);
        accessParameter.setPageIndex(pageIndex);

        return access.searchEntityPageInfo();
    }

	@Override
    @Cacheable(key="#id")
	public  COzBkHeaderEntity getEntityById(String id) throws Exception {
        access.getAccessParameter().getFilter().cleanFilter();
        access.getAccessParameter().getFilter().addEqual(COzBkHeaderTags.JobOrderId,id);
        return (COzBkHeaderEntity) access.searchEntity();
	}

    @Override
    @Cacheable()
    public List<COzBkHeaderEntity> getEntityListByIds(List<? extends Serializable> ids) throws Exception {
        return (List<COzBkHeaderEntity>) access.searchEntityListByIds(ids);
    }

	@Override
	public Map<String, Object> getMapById(String id) throws Exception {
		return null;//access.getMapById(id);
	}

	@Override
	public boolean insert(COzBkHeaderEntity entity) throws Exception {
		return access.insert(entity);
	}

	@Override
	public boolean update(COzBkHeaderEntity entity) throws Exception {
		return access.update(entity);
	}

    @Override
    public boolean updateWithSelective(COzBkHeaderEntity entity) throws Exception {
        return access.updateWithSelective(entity);
    }

	@Override
	public boolean delete(COzBkHeaderEntity entity) throws Exception {
		return access.delete(entity);
	}

	@Override
	public boolean deleteByIdForSingle(Object keyValue) throws Exception {
		return access.deleteByIdForSingle(keyValue);
	}

    @Override
    public boolean deleteBatchIds(List<? extends Serializable> ids, boolean recursive) throws Exception {
        return false;//access.deleteBatchIds(COzBkHeaderEntity.class,ids,recursive);
    }

}